package net.child.chess.puzzles;

import net.child.chess.core.Board;
import net.child.chess.core.BoardParams;
import net.child.chess.pieces.Bishop;
import net.child.chess.pieces.BlackPown;
import net.child.chess.pieces.King;
import net.child.chess.pieces.Knight;
import net.child.chess.pieces.Queen;
import net.child.chess.pieces.Rook;
import net.child.chess.pieces.WhitePown;
import net.child.chess.utils.ChessDef;

public class MateInOne implements IPuzzle
{
	public MateInOne()
	{
		mCurrentPuzzle = 0;
		mBoardParams = new BoardParams(1, ChessDef.Color.BLACK_WHITE, ChessDef.Color.BLACK_WHITE);
	}
	
	@Override
	public String name()
	{
		return "Mate In One";
	}
	
	@Override
	public void randomize(Board board)
	{
		board.reset(mBoardParams);
		int puzzle = (mCurrentPuzzle++ % MAX_PUZZLES) + 1;
		switch(puzzle)
		{
		case 1:
			puzzle1(board);
			break;
		case 2:
			puzzle2(board);
			break;
		case 3:
			puzzle3(board);
			break;
		case 4:
			puzzle4(board);
			break;
		case 5:
			puzzle5(board);
			break;
		case 6:
			puzzle6(board);
			break;
		case 7:
			puzzle7(board);
			break;
		case 8:
			puzzle8(board);
			break;
		case 9:
			puzzle9(board);
			break;
		case 10:
			puzzle10(board);
			break;
		default:
			break;
		};
	}
	
	private void puzzle1(Board board)
	{
		board.add(new Rook(ChessDef.Color.BLACK, 6));
		board.add(new Queen(ChessDef.Color.WHITE, 10));
		board.add(new WhitePown(13));
		board.add(new King(ChessDef.Color.BLACK, 21));
		board.add(new WhitePown(29));
		board.add(new King(ChessDef.Color.WHITE, 37));
	}
	
	private void puzzle2(Board board)
	{
		board.add(new Rook(ChessDef.Color.BLACK, 0));
		board.add(new Bishop(ChessDef.Color.BLACK, 1));
		board.add(new King(ChessDef.Color.BLACK, 8));
		board.add(new BlackPown(10));
		board.add(new Rook(ChessDef.Color.WHITE, 15));
		board.add(new WhitePown(16));
		board.add(new WhitePown(18));
		board.add(new WhitePown(24));
		board.add(new BlackPown(25));
		board.add(new King(ChessDef.Color.WHITE, 26));
		board.add(new Bishop(ChessDef.Color.WHITE, 61));
	}
	
	private void puzzle3(Board board)
	{
		board.add(new King(ChessDef.Color.WHITE, 0));
		board.add(new Knight(ChessDef.Color.WHITE, 22));
		board.add(new Knight(ChessDef.Color.BLACK, 29));
		board.add(new King(ChessDef.Color.BLACK, 36));
		board.add(new Knight(ChessDef.Color.BLACK, 43));
		board.add(new Knight(ChessDef.Color.WHITE, 50));
		board.add(new Queen(ChessDef.Color.WHITE, 56));
	}
	
	private void puzzle4(Board board)
	{
		board.add(new Queen(ChessDef.Color.WHITE, 5));
		board.add(new King(ChessDef.Color.BLACK, 36));
		board.add(new Knight(ChessDef.Color.WHITE, 43));
		board.add(new Knight(ChessDef.Color.WHITE, 41));
		board.add(new King(ChessDef.Color.WHITE, 53));
	}
	
	private void puzzle5(Board board)
	{
		board.add(new Knight(ChessDef.Color.BLACK, 11));
		board.add(new Bishop(ChessDef.Color.BLACK, 12));
		board.add(new BlackPown(19));
		board.add(new King(ChessDef.Color.BLACK, 20));
		board.add(new Knight(ChessDef.Color.BLACK, 29));
		board.add(new Queen(ChessDef.Color.BLACK, 33));
		board.add(new Bishop(ChessDef.Color.WHITE, 56));
		board.add(new Queen(ChessDef.Color.WHITE, 62));
		board.add(new Knight(ChessDef.Color.WHITE, 51));
		board.add(new King(ChessDef.Color.WHITE, 52));
		board.add(new WhitePown(44));
	}
	
	//	#80
	private void puzzle6(Board board)
	{
		board.add(new Knight(ChessDef.Color.BLACK, 2));
		board.add(new Rook(ChessDef.Color.BLACK, 6));
		board.add(new King(ChessDef.Color.BLACK, 8));
		board.add(new BlackPown(13));
		board.add(new BlackPown(15));
		board.add(new Bishop(ChessDef.Color.BLACK, 16));
		board.add(new Queen(ChessDef.Color.BLACK, 21));
		board.add(new BlackPown(24));
		board.add(new BlackPown(26));
		board.add(new BlackPown(35));
		board.add(new WhitePown(32));
		board.add(new WhitePown(43));
		board.add(new WhitePown(50));
		board.add(new WhitePown(53));
		board.add(new Bishop(ChessDef.Color.WHITE, 37));
		board.add(new Bishop(ChessDef.Color.WHITE, 54));
		board.add(new Queen(ChessDef.Color.WHITE, 51));
		board.add(new Rook(ChessDef.Color.WHITE, 57));
		board.add(new King(ChessDef.Color.WHITE, 62));
	}
	
	//	#81
	private void puzzle7(Board board)
	{
		board.add(new Rook(ChessDef.Color.WHITE, 6));
		board.add(new BlackPown(10));
		board.add(new BlackPown(13));
		board.add(new BlackPown(15));
		board.add(new King(ChessDef.Color.BLACK, 12));
		board.add(new Knight(ChessDef.Color.BLACK, 21));
		board.add(new WhitePown(26));
		board.add(new WhitePown(27));
		board.add(new King(ChessDef.Color.WHITE, 28));
		board.add(new WhitePown(37));
		board.add(new Rook(ChessDef.Color.BLACK, 39));
		board.add(new BlackPown(32));
		board.add(new Bishop(ChessDef.Color.WHITE, 40));
	}
	
	//	#88
	private void puzzle8(Board board)
	{
		board.add(new Queen(ChessDef.Color.WHITE, 0));
		board.add(new Rook(ChessDef.Color.WHITE, 1));
		board.add(new Rook(ChessDef.Color.BLACK, 6));
		board.add(new King(ChessDef.Color.BLACK, 7));
		board.add(new BlackPown(14));
		board.add(new BlackPown(22));
		board.add(new BlackPown(29));
		board.add(new Queen(ChessDef.Color.BLACK, 20));
		board.add(new King(ChessDef.Color.WHITE, 56));
		board.add(new WhitePown(49));
		board.add(new WhitePown(40));
		board.add(new BlackPown(32));
	}
	
	//	#93
	private void puzzle9(Board board)
	{
		board.add(new King(ChessDef.Color.BLACK, 4));
		board.add(new King(ChessDef.Color.WHITE, 50));
		board.add(new Queen(ChessDef.Color.BLACK, 60));
		board.add(new Queen(ChessDef.Color.WHITE, 54));
		board.add(new WhitePown(12));
		board.add(new WhitePown(19));
		board.add(new BlackPown(13));
	}
	
	//	#79
	private void puzzle10(Board board)
	{
		board.add(new Rook(ChessDef.Color.BLACK, 2));
		board.add(new Rook(ChessDef.Color.BLACK, 3));
		board.add(new BlackPown(10));
		board.add(new King(ChessDef.Color.BLACK, 11));
		board.add(new Bishop(ChessDef.Color.WHITE, 13));
		board.add(new BlackPown(14));
		board.add(new BlackPown(17));
		board.add(new WhitePown(25));
		board.add(new WhitePown(26));
		board.add(new Bishop(ChessDef.Color.WHITE, 33));
		board.add(new BlackPown(35));
		board.add(new BlackPown(37));
		board.add(new WhitePown(45));
		board.add(new King(ChessDef.Color.WHITE, 53));
		board.add(new Rook(ChessDef.Color.WHITE, 62));
	}
	
	private int mCurrentPuzzle;
	private static final int MAX_PUZZLES = 10;
	private BoardParams mBoardParams;
}